from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-04-14 14:02:15.111559
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 14, Apr, 2022
Time: 14:02:20
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.9559
Nobs: 626.000 HQIC: -49.3461
Log likelihood: 7618.66 FPE: 2.89443e-22
AIC: -49.5941 Det(Omega_mle): 2.50968e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.332672 0.063452 5.243 0.000
L1.Burgenland 0.105772 0.039837 2.655 0.008
L1.Kärnten -0.110514 0.020862 -5.297 0.000
L1.Niederösterreich 0.196690 0.083278 2.362 0.018
L1.Oberösterreich 0.119343 0.082079 1.454 0.146
L1.Salzburg 0.260008 0.042269 6.151 0.000
L1.Steiermark 0.042809 0.055653 0.769 0.442
L1.Tirol 0.104703 0.045014 2.326 0.020
L1.Vorarlberg -0.065436 0.039762 -1.646 0.100
L1.Wien 0.020320 0.073021 0.278 0.781
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.041981 0.135906 0.309 0.757
L1.Burgenland -0.036653 0.085325 -0.430 0.668
L1.Kärnten 0.041795 0.044683 0.935 0.350
L1.Niederösterreich -0.200275 0.178370 -1.123 0.262
L1.Oberösterreich 0.456202 0.175801 2.595 0.009
L1.Salzburg 0.282703 0.090535 3.123 0.002
L1.Steiermark 0.110864 0.119200 0.930 0.352
L1.Tirol 0.307096 0.096414 3.185 0.001
L1.Vorarlberg 0.027253 0.085165 0.320 0.749
L1.Wien -0.022635 0.156401 -0.145 0.885
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.188217 0.032450 5.800 0.000
L1.Burgenland 0.089190 0.020373 4.378 0.000
L1.Kärnten -0.007330 0.010669 -0.687 0.492
L1.Niederösterreich 0.245662 0.042589 5.768 0.000
L1.Oberösterreich 0.160881 0.041976 3.833 0.000
L1.Salzburg 0.040269 0.021617 1.863 0.062
L1.Steiermark 0.027270 0.028461 0.958 0.338
L1.Tirol 0.083450 0.023020 3.625 0.000
L1.Vorarlberg 0.055046 0.020335 2.707 0.007
L1.Wien 0.118918 0.037343 3.184 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.109541 0.032494 3.371 0.001
L1.Burgenland 0.042981 0.020400 2.107 0.035
L1.Kärnten -0.013231 0.010683 -1.239 0.216
L1.Niederösterreich 0.174556 0.042646 4.093 0.000
L1.Oberösterreich 0.334190 0.042032 7.951 0.000
L1.Salzburg 0.100217 0.021646 4.630 0.000
L1.Steiermark 0.112488 0.028499 3.947 0.000
L1.Tirol 0.091385 0.023051 3.964 0.000
L1.Vorarlberg 0.061145 0.020362 3.003 0.003
L1.Wien -0.013943 0.037394 -0.373 0.709
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.110269 0.060789 1.814 0.070
L1.Burgenland -0.044437 0.038165 -1.164 0.244
L1.Kärnten -0.045685 0.019986 -2.286 0.022
L1.Niederösterreich 0.140026 0.079782 1.755 0.079
L1.Oberösterreich 0.162366 0.078633 2.065 0.039
L1.Salzburg 0.284720 0.040495 7.031 0.000
L1.Steiermark 0.058862 0.053317 1.104 0.270
L1.Tirol 0.160307 0.043125 3.717 0.000
L1.Vorarlberg 0.098851 0.038093 2.595 0.009
L1.Wien 0.076956 0.069956 1.100 0.271
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.053210 0.047621 1.117 0.264
L1.Burgenland 0.026548 0.029897 0.888 0.375
L1.Kärnten 0.052961 0.015657 3.383 0.001
L1.Niederösterreich 0.196650 0.062500 3.146 0.002
L1.Oberösterreich 0.332091 0.061600 5.391 0.000
L1.Salzburg 0.036201 0.031723 1.141 0.254
L1.Steiermark 0.011666 0.041767 0.279 0.780
L1.Tirol 0.121612 0.033783 3.600 0.000
L1.Vorarlberg 0.067332 0.029841 2.256 0.024
L1.Wien 0.102574 0.054802 1.872 0.061
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.165918 0.057227 2.899 0.004
L1.Burgenland 0.005381 0.035928 0.150 0.881
L1.Kärnten -0.065706 0.018815 -3.492 0.000
L1.Niederösterreich -0.103577 0.075107 -1.379 0.168
L1.Oberösterreich 0.207347 0.074026 2.801 0.005
L1.Salzburg 0.054561 0.038122 1.431 0.152
L1.Steiermark 0.246800 0.050192 4.917 0.000
L1.Tirol 0.501465 0.040598 12.352 0.000
L1.Vorarlberg 0.064069 0.035861 1.787 0.074
L1.Wien -0.073871 0.065857 -1.122 0.262
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.150892 0.063433 2.379 0.017
L1.Burgenland -0.002091 0.039825 -0.053 0.958
L1.Kärnten 0.062575 0.020855 3.000 0.003
L1.Niederösterreich 0.171634 0.083253 2.062 0.039
L1.Oberösterreich -0.055373 0.082054 -0.675 0.500
L1.Salzburg 0.207946 0.042256 4.921 0.000
L1.Steiermark 0.138436 0.055636 2.488 0.013
L1.Tirol 0.058038 0.045000 1.290 0.197
L1.Vorarlberg 0.147151 0.039750 3.702 0.000
L1.Wien 0.123340 0.072999 1.690 0.091
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.379142 0.037403 10.137 0.000
L1.Burgenland -0.003232 0.023482 -0.138 0.891
L1.Kärnten -0.020729 0.012297 -1.686 0.092
L1.Niederösterreich 0.205051 0.049089 4.177 0.000
L1.Oberösterreich 0.230757 0.048382 4.769 0.000
L1.Salzburg 0.037251 0.024916 1.495 0.135
L1.Steiermark -0.012296 0.032805 -0.375 0.708
L1.Tirol 0.089320 0.026534 3.366 0.001
L1.Vorarlberg 0.052761 0.023438 2.251 0.024
L1.Wien 0.044419 0.043043 1.032 0.302
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036949 0.111115 0.173526 0.139890 0.102290 0.082253 0.036542 0.212363
Kärnten 0.036949 1.000000 -0.024133 0.132256 0.050632 0.086921 0.443760 -0.065457 0.090096
Niederösterreich 0.111115 -0.024133 1.000000 0.317432 0.124987 0.278217 0.070447 0.156087 0.294836
Oberösterreich 0.173526 0.132256 0.317432 1.000000 0.216365 0.299634 0.168342 0.139815 0.241990
Salzburg 0.139890 0.050632 0.124987 0.216365 1.000000 0.128145 0.094519 0.107143 0.127189
Steiermark 0.102290 0.086921 0.278217 0.299634 0.128145 1.000000 0.136244 0.111270 0.039275
Tirol 0.082253 0.443760 0.070447 0.168342 0.094519 0.136244 1.000000 0.066668 0.151809
Vorarlberg 0.036542 -0.065457 0.156087 0.139815 0.107143 0.111270 0.066668 1.000000 -0.002463
Wien 0.212363 0.090096 0.294836 0.241990 0.127189 0.039275 0.151809 -0.002463 1.000000